package com.ztools.pc.controller.information;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ztools.common.model.pc.information.WeChatMember;
import com.ztools.common.util.common.PageUtil;
import com.ztools.common.util.common.Result;
import com.ztools.pc.service.information.MemberService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author:seeTools
 * @Date: 2023/4/14  21:06
 * @Version 1.0
 */
@RestController
@RequestMapping("/weChat/member")
public class MemberController {

    @Resource
    private MemberService memberService;

    @RequestMapping("/list")
    public Result findList(@RequestBody PageUtil<WeChatMember> pageUtil) {
        Page<WeChatMember> list = memberService.findList(pageUtil);
        return list != null ? Result.success("查询成功").data(list) : Result.error();
    }

    @RequestMapping("/findByObject")
    public Result findByObject(@RequestBody WeChatMember weChatMember) {
        List<WeChatMember> list = memberService.findByObject(weChatMember);
        return list != null ? Result.success("查询成功").data(list) : Result.error();
    }

    @RequestMapping("/add")
    public Result add(@RequestBody WeChatMember weChatMember) {
        boolean b = memberService.add(weChatMember);
        return b ? Result.success("添加成功") : Result.error("添加失败");
    }

    @RequestMapping("/update")
    public Result update(@RequestBody WeChatMember weChatMember) {
        boolean b = memberService.update(weChatMember);
        return b ? Result.success("修改成功") : Result.error("修改失败");
    }

    @RequestMapping("delete")
    public Result delete(@RequestBody WeChatMember weChatMember) {
        boolean b = memberService.delete(weChatMember);
        return b ? Result.success("删除成功") : Result.error("删除失败");
    }

    @RequestMapping("/export")
    public void excel(HttpServletResponse response, @RequestBody WeChatMember weChatMember) {
        memberService.exportExcel(response, weChatMember);
    }

}
